<?php

/**
 * @Author:             wuchenge
 * @Date:               2025-03-05 14:26:55
 * @Last Modified by:   wuchenge
 */
namespace App\Transformer;

use App\Libraries\Utils;

class UserTransformer extends Transformer
{

    /**
     * [transform description]
     * @param  [type] $lesson [description]
     * @return [type]         [description]
     */
    public function transform($user)
    {
        // 说明是集合 Illuminate
        if (!is_array($user)) {
            $user = $user->toArray();
        }

        $user_transform = [
            'id'          => $user['id'],
            'nick_name'   => $user['info']['nick_name'],
            'avatar'      => Utils::getImage($user['info']['avatar']),
            'status'      => $user['status'],
            'created_at'  => $user['created_at'],
            'email'       => $user['email'],
            'levels'      => $user['info']['levels'],
            'telegram'    => $user['info']['telegram'],
            'points'      => $user['info']['points'],
            'invite_code' => $user['invite_code'],
            'level_name'  => $user['info']['level']['name'],
        ];

        if (isset($user['children_count'])) {
            $user_transform['children_count'] = $user['children_count'];
        }

        return $user_transform;
    }
}
